package org.example;

import org.example.beans.User;
import org.example.config.ApplicationContextConfig;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.stereotype.Component;

/**
 * Hello world!
 *
 * 运行结果：org.example.beans.User@5f354bcf
 */
@Component
public class App {
    public static void main(String[] args) {

        //注解方式
        /*ApplicationContext applicationContext = new AnnotationConfigApplicationContext(ApplicationContextConfig.class);
        User user = applicationContext.getBean(User.class);
        System.out.println(user.getName());  //zs
        */

        //xml方式获取bean
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("applicationContext.xml");
        User user = (User) applicationContext.getBean("user");
        System.out.println(user.getName());

    }
}
